package top.happylaishop.shop.controller.fontend;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import top.happylaishop.shop.dto.ShippingDto;
import top.happylaishop.shop.service.CommonService;
import top.happylaishop.shop.service.ShippingService;
import top.happylaishop.shop.utils.PageDto;
import top.happylaishop.shop.utils.resp.BaseResponse;
import top.happylaishop.shop.utils.resp.RestResponse;

/**
 * Created by geely
 */

@Controller
@RequestMapping("/shipping/")
public class ShippingController {


    @Autowired
    private ShippingService shippingService;
    @Autowired
    private CommonService commonService;


    @PostMapping("/add")
    @ResponseBody
    public BaseResponse add(@RequestBody ShippingDto shippingDto){
        return shippingService.add(shippingDto, commonService.getCurrentUserInfo());
    }


    @PostMapping("/delete/{shippingId}")
    @ResponseBody
    public BaseResponse delete(@PathVariable Integer shippingId){
        return shippingService.delete(shippingId, commonService.getCurrentUserInfo());
    }

    @RequestMapping("/update")
    @ResponseBody
    public BaseResponse update(@RequestBody ShippingDto shippingDto){
        return shippingService.update(shippingDto, commonService.getCurrentUserInfo());
    }

    @RequestMapping("/updateDefaultShipping/{shippingId}")
    @ResponseBody
    public BaseResponse updateDefaultShipping(@PathVariable Integer shippingId){
        return shippingService.updateDefaultShipping(commonService.getCurrentUserInfo(), shippingId);
    }

    @RequestMapping("/select/{shippingId}")
    @ResponseBody
    public RestResponse<ShippingDto> select(@PathVariable Integer shippingId){
        return shippingService.select(commonService.getCurrentUserInfo(), shippingId);
    }


    @GetMapping("/list/{pageNum}/{pageSize}")
    @ResponseBody
    public RestResponse<PageDto<ShippingDto>> list(@PathVariable Integer pageNum, @PathVariable Integer pageSize){
        PageDto<ShippingDto> shippingDtoPageDto = new PageDto<>();
        shippingDtoPageDto.setPage(pageNum == null ? 1 : pageNum);
        shippingDtoPageDto.setSize(pageSize == null ? 1 : pageSize);
        return shippingService.list(shippingDtoPageDto, commonService.getCurrentUserInfo());
    }














}
